import librosa
import librosa.display
import numpy as np
import FileName
import spec
import random
import os
from os import listdir

# music_names = listdir(r'C:\Users\YMXD\ESC\Dataset\ESC-10')
music_names = listdir(r'D:\数据集\Dataset\ESC-50') #获取文件夹内文件的名字




for name in music_names:

 #ESC-10
 # filepath = r'C:\Users\YMXD\ESC\Dataset\ESC-10' + '/' + name  # 原始音频音频文件
 # makirpath = r'C:\Users\YMXD\ESC\Spec\ESC-10\train' + '/' + name  # 生成频谱图地址
 # makirpathTest = r'C:\Users\YMXD\ESC\Spec\ESC-10\test' + '/' + name

 #ESC-50
 filepath = r'D:\数据集\Dataset\ESC-50' + '/' + name  # 原始音频音频文件
 makirpath = r'D:\数据集\Spec\ESC-50\train' + '/' + name  # 生成频谱图地址
 makirpathTest = r'D:\数据集\Spec\ESC-50\test' + '/' + name
 # os.mkdir(makirpath)


 music_list=FileName.getlist(filepath)
 print(music_list)

 #制作训练集
 for name in music_list[:35]:
    # try:
     pathname=filepath+'/'+name
     # spec.getMel(pathname, name, makirpath)
     # spec.time_warp(pathname, name, makirpath)
     spec.freq_mask(pathname, name, makirpath)


    # except:
    #  continue

 #制作测试集
 # for name in music_list[35:]:
 #    # try:
 #    #  print("name:",name)
 #     pathname=filepath+'/'+name
 #     spec.getMel(pathname, name, makirpathTest)
 #
 #
 #    # except:
 #    #  continue
